package com.wsd.serviceImpl;

import com.wsd.dao.LoanInformationMapper;
import com.wsd.dao.RepaymentPlanMapper;
import com.wsd.domain.NormalLoan;
import com.wsd.domain.OverdueLoan;
import com.wsd.service.SOverdueLoanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Classname SOverdueLoanServiceImpl
 * @Description TODO
 * @Date 2020/7/20 10:59
 * @Created by niuxiaojuan
 */
@Service
public class SOverdueLoanServiceImpl implements SOverdueLoanService {
    @Autowired
    RepaymentPlanMapper repaymentPlanMapper;
    @Autowired
    LoanInformationMapper loanInformationMapper;
    @Override
    public BigDecimal sumSOverdueLoan(){
        List<Long> list=repaymentPlanMapper.findSOverdueGroup();
        return loanInformationMapper.sumLoanMoney(list);
    }

    @Override
    public BigDecimal sumRepayLoanMoney() {
        List<Long> list=repaymentPlanMapper.findSOverdueGroup();
        BigDecimal remianMoney=loanInformationMapper.sumRemainPrincipal(list);
        return loanInformationMapper.sumLoanMoney(list).subtract(remianMoney);
    }

    @Override
    public BigDecimal findSOverInterest() {
        return repaymentPlanMapper.findSOverInterest();
    }

    @Override
    public BigDecimal sumRepayInterest() {
        return repaymentPlanMapper.sumRepayInterest(repaymentPlanMapper.findSOverdueGroup());
    }

    @Override
    public BigDecimal sumSOverdueMoney() {
        return repaymentPlanMapper.sumSOverdueMoney();
    }

    @Override
    public BigDecimal sumSOverdueInterest() {
        return repaymentPlanMapper.sumSOverdueInterest();
    }

    @Override
    public List<OverdueLoan> findSOverLoanForm(int pagenum,int num) {
        List<OverdueLoan> list=repaymentPlanMapper.findSOverLoanForm((pagenum-1)*num,num);
        for(OverdueLoan n:list)
        {
            NormalLoan temp=loanInformationMapper.findFormInfoById(n.getLoanId());
            n.setUserId(temp.getUserId());
            n.setLoanAmount(temp.getLoanAmount());
            n.setRepayAmount(temp.getRepayAmount());
        }
        return list;
    }

    @Override
    public Long countSOverLoanForm() {
        return repaymentPlanMapper.countSOverLoanForm();
    }
}
